package fr.generali.accueilclient.gwt.client.ui.components.form.formitem;

import com.google.gwt.editor.client.LeafValueEditor;
import com.google.gwt.user.client.ui.SimplePanel;


/**
 * Champ permettant de repr�senter une valeur {@link Boolean} sous form d'une
 * image vrai/faux.<br>
 * FIXME: impl�menter �dition et compagnie (pas de spec � ce jour)
 */
public class BooleanFormItem extends LabelFormItem<Boolean> implements LeafValueEditor<Boolean> {

    SimplePanel boolWidget;
    Boolean boolValue;

    public BooleanFormItem() {
        super(new SimplePanel());
        this.boolWidget = (SimplePanel ) editableWidget;
    }

    @Override
    protected boolean isDataFilled() {
        return true;
    }

    @Override
    protected void doSetValue(Boolean value, boolean valueIsNullOrEmpty) {
        boolValue = value;
        if (valueIsNullOrEmpty || Boolean.FALSE.equals(value)) {
            valueLabel.removeStyleName(res.style().affirmative());
            valueLabel.addStyleName(res.style().negative());
        } else {
            valueLabel.removeStyleName(res.style().negative());
            valueLabel.addStyleName(res.style().affirmative());
        }
    }

    @Override
    protected boolean valueIsNullOrEmpty(Boolean value) {
        return value == null;
    }

    @Override
    public Boolean getValue() {
        return boolValue;
    }

    // @Override
    // protected void addHandlerForDonneeCle() {
    // // TODO Auto-generated method stub
    //
    // }

}
